package com.adou.d10.annotation;

import com.adou.d8.thread.Demo;
import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * 解析注解
 */
public class AnnotationTest3 {

    @Test
    public void parseClass(){
       // 1.先得到class对象
        Class c = Demo1.class;

        // 2.解析类似注解
        // 判断类上是否包含某个注解
        if(c.isAnnotationPresent(MyTest4.class)) {
            MyTest4 myTest4 = (MyTest4) c.getDeclaredAnnotation(MyTest4.class);

            System.out.println(myTest4.value());
            System.out.println(myTest4.aaa());
            System.out.println(Arrays.toString(myTest4.bbb()));
        }
    }


    public void parseMethod() throws NoSuchMethodException {
        // 1.先得到class对象
        Class c = Demo1.class;
        Method m = c.getDeclaredMethod("test1");

        // 2.解析类似注解
        // 判断方法上是否包含某个注解
        if (c.isAnnotationPresent(MyTest4.class)) {
            MyTest4 myTest4 = (MyTest4) m.getDeclaredAnnotation(MyTest4.class);

            System.out.println(myTest4.value());
            System.out.println(myTest4.aaa());
            System.out.println(Arrays.toString(myTest4.bbb()));
        }
    }
}
